﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCDto.IM.LeaveMessageRecord;
using BCService.IM.LeaveMessageRecordService;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management
{
    /// <summary>
    /// 留言记录控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    [Obsolete]
    public class LeaveMessagesController : ManagementBaseController
    {
        private readonly ILeaveMessageRecordService leaveMessageRecordService;

        public LeaveMessagesController(ILeaveMessageRecordService leaveMessageRecordService)
        {
            this.leaveMessageRecordService = leaveMessageRecordService;
        }

        /// <summary>
        /// 获取留言记录列表（分页）。
        /// </summary>
        /// <param name="isRead">是否已读</param>
        /// <param name="isReply">是否已回复</param>
        /// <param name="replyAdminName">回复人</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">每页数据条数</param>
        /// <param name="ascending">排序</param>
        /// <response code="200">返回留言记录列表（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<LeaveMessageRecordDto>), 200)]
        [Obsolete]
        public IActionResult Query([FromQuery(Name = "is_read")]bool? isRead,
            [FromQuery(Name = "is_reply")]bool? isReply,
            [FromQuery(Name = "reply_admin_name")]string replyAdminName,
            [FromQuery(Name = "start_time")]DateTime? start,
            [FromQuery(Name = "end_time")]DateTime? end,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10,
            [FromQuery(Name = "ascending")]bool? ascending = null)
        {
            return this.Ok(this.leaveMessageRecordService.Query(isRead, isReply, replyAdminName, start, end, ascending, index, size));
        }

        #region 标记留言记录已读
        /// <summary>
        /// 标记留言记录已读
        /// </summary>
        /// <param name="leaveMessageRecordId">留言记录Id</param>
        /// <response code="200">留言记录。</response>
        /// <returns></returns>
        [HttpPost("[action]/{leave_message_id}")]
        [Log("标记留言记录已读")]
        [ProducesResponseType(typeof(LeaveMessageRecordDto), 200)]
        [Obsolete]
        public IActionResult ReadMessage([FromRoute(Name = "leave_message_id")]long leaveMessageRecordId)
        {
            return this.Ok(this.leaveMessageRecordService.UpdateIsRead(leaveMessageRecordId, this.Admin));
        }
        #endregion

        #region 留言回复记录
        /// <summary>
        /// 留言回复记录
        /// </summary>
        /// <param name="leaveMessageRecordId">留言记录Id</param>
        /// <param name="leaveMessageRecordPutDto">回复留言记录</param>
        /// <response code="200">留言记录。</response>
        /// <returns></returns>
        [HttpPost("[action]/{leave_message_id}")]
        [Log("留言回复")]
        [ProducesResponseType(typeof(LeaveMessageRecordDto), 200)]
        [Obsolete]
        public IActionResult Reply([FromRoute(Name = "leave_message_id")]long leaveMessageRecordId, [FromBody]LeaveMessageRecordPutDto leaveMessageRecordPutDto)
        {
            leaveMessageRecordPutDto.ReplyAdminId = this.Admin.AdminId;
            leaveMessageRecordPutDto.ReplyUserName = this.Admin.FullName;
            return this.Ok(this.leaveMessageRecordService.UpdateReplyInfo(leaveMessageRecordId, leaveMessageRecordPutDto));
        }
        #endregion

        /// <summary>
        /// 查询客服今日统计
        /// </summary>
        /// <response code="200">返回客服今日统计</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(LeaveMessageCountDto), 200)]
        [Obsolete]
        public IActionResult QueryCount()
        {
            return this.Ok(this.leaveMessageRecordService.QueryCount());
        }
    }
}